package hn.sigit.model.hnd.administrative;

import java.util.List;

import hn.sigit.model.hnd.cadastre.HND_Layer;
import hn.sigit.model.hnd.cadastre.HND_SpatialZone;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="HND_MaintenanceTransaction", schema="hnd_administrative")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorValue("HND_MaintenanceTransaction")
@PrimaryKeyJoinColumn(name="TransactionID", referencedColumnName="ID")
public class HND_MaintenanceTransaction extends HND_Transaction {
	private static final long serialVersionUID = 1L;

	private HND_Layer workingLayer;
	private List<HND_SpatialZone> involvedSpatialZones;
	private Long presentationId;
	

	@ManyToOne(targetEntity=HND_Layer.class, optional=false, fetch=FetchType.LAZY)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
	@JoinColumns({ @JoinColumn(name="WorkingLayerID", referencedColumnName="LA_LevelID") })
	@org.hibernate.annotations.LazyToOne(value=org.hibernate.annotations.LazyToOneOption.NO_PROXY)
	public HND_Layer getWorkingLayer() {
		return workingLayer;
	}
	public void setWorkingLayer(HND_Layer workingLayer) {
		this.workingLayer = workingLayer;
	}
	
	@ManyToMany(targetEntity=HND_SpatialZone.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})
	@JoinTable(name="HND_MaintenanceTransaction__HND_SpatialZone", schema="hnd_administrative", joinColumns={ @JoinColumn(name="HND_MaintenanceTransactionID") }, inverseJoinColumns={ @JoinColumn(name="HND_SpatialZoneID") })	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)
	public List<HND_SpatialZone> getInvolvedSpatialZones() {
		return involvedSpatialZones;
	}
	public void setInvolvedSpatialZones(List<HND_SpatialZone> involvedSpatialZones) {
		this.involvedSpatialZones = involvedSpatialZones;
	}
	

	@Override
	@Column(name="PresentationId", nullable=false, insertable=false, updatable=false, columnDefinition="serial")//warning: serial is Postgres specific
	public Long getPresentationId() {
		return presentationId;
	}
	protected void setPresentationId(Long value) {
		this.presentationId = value;
	}
}
